{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Проверка гипотез"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install torchvision"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn.functional as F\n",
    "from torch import nn\n",
    "from torch.utils.data import DataLoader\n",
    "from torchvision import datasets\n",
    "from torchvision.transforms import ToTensor    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class SupervisedKernel(nn.Module):\n",
    "    def __init__(self, kernel: nn.Module = None, supervisor: nn.Module = None):\n",
    "        super(SupervisedKernel, self).__init__()\n",
    "        if(kernel is not None):\n",
    "            self.kernel = kernel\n",
    "        else:\n",
    "            self.kernel = nn.Sequential(nn.Linear(8, 8), nn.ReLU())\n",
    "        self.superviser = supervisor\n",
    "        if(self.superviser is not None):\n",
    "            self.superviser.requires_grad_(False)\n",
    "\n",
    "    def forward(self, x):\n",
    "        y = self.kernel(x)\n",
    "        if(self.superviser is not None):\n",
    "            target = self.superviser(x)\n",
    "        else:\n",
    "            target = y\n",
    "        return y, target\n",
    "    \n",
    "    @classmethod\n",
    "    def is_supervised(self, module: nn.Module):\n",
    "        return isinstance(module, SupervisedKernel) and (module.superviser is not None)\n",
    "    \n",
    "    def update(self, kernel: nn.Module, retrain: bool = True):\n",
    "        # прежнее ядро становится супервизором\n",
    "        self.superviser = self.kernel.requires_grad_(False)\n",
    "        self.kernel = kernel\n",
    "\n",
    "    def advise(self, x):\n",
    "        # TODO метод оценки \"надзороного ядра\"\n",
    "        pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
